package com.xoa.service.hr;

import com.xoa.dao.common.HrCodeMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.hr.HrStaffReinstatementMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.common.HrCode;
import com.xoa.model.department.Department;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.hr.HrRehab;
import com.xoa.model.hr.HrStaffReinstatement;
import com.xoa.model.hr.HrStaffReinstatementWithBLOBs;
import com.xoa.model.hr.HrWorkExperienceWithBLOBs;
import com.xoa.model.users.Users;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ExcelUtil;
import com.xoa.util.GetAttachmentListUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.page.PageParams;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.util.*;

@Service
public class HrStaffReinstatementService {

    @Autowired
    private HrStaffReinstatementMapper hrStaffReinstatementMapper;
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    HrCodeMapper hrCodeMapper;
    @Autowired
    UsersMapper usersMapper;
    /**
     * 添加
     * 郭心雨
     * 2018.07.19
     * @param  hrStaffReinstatement
     * @return
     */
    public ToJson addRehab(HttpServletRequest request,HrStaffReinstatementWithBLOBs hrStaffReinstatement) {
        ToJson toJson=new ToJson();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
        hrStaffReinstatement.setCreateUserId(users.getUserId());
        hrStaffReinstatement.setCreateDeptId(users.getDeptId());
        if (hrStaffReinstatement.getReinstatementPerson()!=null){
            String[] str=hrStaffReinstatement.getReinstatementPerson().split(",");
            hrStaffReinstatement.setReinstatementPerson(str[0]);
        }
        hrStaffReinstatement.setDespacho(hrStaffReinstatement.getReappointmentType());
        hrStaffReinstatement.setDespachoPerson(users.getUserId());
        int count=hrStaffReinstatementMapper.insertSelective(hrStaffReinstatement);
        if(count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 批量删除
     * 郭心雨
     * 2018.07.19
     * @param reinstatementId
     * @return
     */
    public ToJson delRehab(Integer[] reinstatementId) {
        ToJson toJson=new ToJson();
        int count=hrStaffReinstatementMapper.deleteById(reinstatementId);
        if(count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }
    /**
     * 修改
     * 郭心雨
     * 2018.07.19
     * @param hrStaffReinstatement
     * @return
     */
    public ToJson modifyRehab(HrStaffReinstatementWithBLOBs hrStaffReinstatement) {
        ToJson toJson=new ToJson();
        if (hrStaffReinstatement.getReinstatementPerson()!=null){
            String[] str=hrStaffReinstatement.getReinstatementPerson().split(",");
            hrStaffReinstatement.setReinstatementPerson(str[0]);
        }
        int count=hrStaffReinstatementMapper.updateByPrimaryKeySelective(hrStaffReinstatement);
        if(count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 根据id查询详情
     * 郭心雨
     * 2018.07.19
     * @param reinstatementId
     * @return
     */
    public ToJson selRehabById(HttpServletRequest request,Integer reinstatementId) {
        ToJson toJson=new ToJson();
        HrStaffReinstatementWithBLOBs hrRehab=hrStaffReinstatementMapper.selRehabById(reinstatementId);
        if(hrRehab.getReappointmentType()!=null){
            //附件处理
            List<Attachment> attachmentList= GetAttachmentListUtil.returnAttachment(hrRehab.getAttachmentName(),hrRehab.getAttachmentId(),"xoa" + (String) request.getSession().getAttribute("loginDateSouse"), "sdas");
            hrRehab.setAttachmentList(attachmentList);
            if (hrRehab.getReappointmentDept()!=null){
                String[] depts=hrRehab.getReappointmentDept().split(",");
                for (String dept:depts){
                    String deptName=departmentMapper.departmentOneSelect(Integer.parseInt(dept));
                    if(!"".equals(deptName)&&deptName!=null){
                        hrRehab.setReappointmentTypeStr(deptName);
                    }else{
                        hrRehab.setReappointmentTypeStr("该部门已删除");
                    }
                }
            }else{
                hrRehab.setReappointmentTypeStr("该部门已删除");
            }
            //查用户名
            if(hrRehab.getCreateUserId()!=null&&hrRehab.getCreateUserId()!=""){
                Users u=usersMapper.getUsersByuserId(hrRehab.getCreateUserId());
                hrRehab.setCreateUserId(u.getUserName());
            }else{
                hrRehab.setCreateUserId("用户不存在");
            }
            //查用户名
            if(hrRehab.getReinstatementPerson()!=null&&hrRehab.getReinstatementPerson()!=""){
                Users u=usersMapper.getUsersByuserId(hrRehab.getReinstatementPerson());
                if(u!=null) {
                    hrRehab.setReinstatementPerson(u.getUserName());
                }
            }else{
                hrRehab.setReinstatementPerson("用户不存在");
            }
        }
        if(hrRehab!=null){
            toJson.setFlag(0);
            toJson.setMsg("ok");
            toJson.setObject(hrRehab);
        }else{
            toJson.setFlag(1);
            toJson.setMsg("err");
        }
        return toJson;
    }

    /**
     * 查看列表
     * 郭心雨
     * 2018.07.19
     * @return
     */
    public ToJson selAllRehab(HttpServletRequest request,Integer page,Integer pageSize,Boolean useFlag,String reinstatementPerson) {
        ToJson toJson=new ToJson();
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page", pageParams);
        map.put("reinstatementPerson",reinstatementPerson);
        List<HrStaffReinstatementWithBLOBs> hrRehabList=hrStaffReinstatementMapper.selAllRehab(map);
        for(HrStaffReinstatementWithBLOBs hrStaff:hrRehabList){
            //附件处理
            List<Attachment> attachmentList= GetAttachmentListUtil.returnAttachment(hrStaff.getAttachmentName(),hrStaff.getAttachmentId(),"xoa" + (String) request.getSession().getAttribute("loginDateSouse"), GetAttachmentListUtil.WORKEXPERIENCE);
            hrStaff.setAttachmentList(attachmentList);
            if (hrStaff.getReappointmentDept()!=null){
                String[] depts=hrStaff.getReappointmentDept().split(",");
                for (String dept:depts){
                    String deptName=departmentMapper.departmentOneSelect(Integer.parseInt(dept));
                    if(!"".equals(deptName)&&deptName!=null){
                        hrStaff.setReappointmentTypeStr(deptName);
                    }else{
                        hrStaff.setReappointmentTypeStr("该部门已删除");
                    }
                }
            }else{
                hrStaff.setReappointmentTypeStr("该部门已删除");
            }
            //查创建者用户名
            if(hrStaff.getCreateUserId()!=null&&hrStaff.getCreateUserId()!=""){
                Users u=usersMapper.getUsersByuserId(hrStaff.getCreateUserId());
                hrStaff.setCreateUserId(u.getUserName());
            }else{
                hrStaff.setCreateUserId("用户不存在");
            }
            //查用户名
            if(hrStaff.getReinstatementPerson()!=null&&hrStaff.getReinstatementPerson()!=""){
                Users u=usersMapper.getUsersByuserId(hrStaff.getReinstatementPerson());
                if(u!=null) {
                    hrStaff.setReinstatementPerson(u.getUserName());
                }
            }else{
                hrStaff.setReinstatementPerson("用户不存在");
            }
        }
        if(hrRehabList.size()>0){
            toJson.setFlag(0);
            toJson.setMsg("ok");
            toJson.setObj(hrRehabList);
            toJson.setTotleNum(pageParams.getTotal());
        }else{
            toJson.setFlag(1);
            toJson.setMsg("err");
        }
        return toJson;
    }


    /**
     * 导入
     * 郭心雨
     * @param request
     * @param response
     * @param file
     * @param session
     * @return
     */
    public ToJson<HrStaffReinstatementWithBLOBs> inputFixAsserts(HttpServletRequest request, HttpServletResponse response, MultipartFile file, HttpSession session) {
        ToJson<HrStaffReinstatementWithBLOBs> json = new ToJson<HrStaffReinstatementWithBLOBs>();
        // 成功次数
        Integer successCount = 0;
        InputStream in=null;
        try {
            //判读当前系统
            //读取配置文件
            ResourceBundle rb = ResourceBundle.getBundle("upload");
            String osName = System.getProperty("os.name");
            StringBuffer path = new StringBuffer();
               StringBuffer buffer=new StringBuffer();
        if(osName.toLowerCase().startsWith("win")){
            //sb=sb.append(rb.getString("upload.win"));
            //判断路径是否是相对路径，如果是的话，加上运行的路径
            String uploadPath = rb.getString("upload.win");
            if(uploadPath.indexOf(":")==-1){
                //获取运行时的路径
                String basePath = this.getClass().getClassLoader().getResource(".").getPath()+ File.pathSeparator;
                //获取截取后的路径
                String str2 = "";
                if(basePath.indexOf("/xoa")!=-1){
                    //获取字符串的长度
                    int length = basePath.length();
                    //返回指定字符在此字符串中第一次出现处的索引
                    int index = basePath.indexOf("/xoa");
                    //从指定位置开始到指定位置结束截取字符串
                    str2=basePath.substring(0,index);
                }
                path = path.append(str2 + "/xoa");
            }
            path.append(uploadPath);
            buffer=buffer.append(rb.getString("upload.win"));
        }else{
            path=path.append(rb.getString("upload.linux"));
            buffer=buffer.append(rb.getString("upload.linux"));
        }
            // 判断是否为空文件
            if (file.isEmpty()) {
                json.setMsg("请上传文件！");
                json.setFlag(1);
                return json;
            } else {
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                    int pos = fileName.indexOf(".");
                    String extName = fileName.substring(pos);
                    String newFileName = uuid + extName;
                    File dest = new File(path.toString(), newFileName);
                    file.transferTo(dest);
                    // 将文件上传成功后进行读取文件
                    // 进行读取的路径
                    String readPath = path.append("\\"+newFileName).toString();
                    in = new FileInputStream(readPath);
                    HSSFWorkbook excelObj = new HSSFWorkbook(in);
                    HSSFSheet sheetObj = excelObj.getSheetAt(0);
                    Row row = sheetObj.getRow(0);
                    int colNum = row.getPhysicalNumberOfCells();
                    int lastRowNum = sheetObj.getLastRowNum();
                    List<HrRehab> saveList = new ArrayList<HrRehab>();
                    HrStaffReinstatementWithBLOBs hrRehab=null;
                    for (int i = 1; i <= lastRowNum; i++) {
                        hrRehab =new HrStaffReinstatementWithBLOBs();
                        row = sheetObj.getRow(i);
                        if (row != null) {
                            for (int j = 0; j < colNum; j++) {
                                Cell cell = row.getCell(j);
                                if (cell != null) {
                                    switch (j) {
                                        case 0:
                                            //姓名
                                            //根据姓名查出员工id
                                            if(getCellValue(cell)!=null&&getCellValue(cell)!=""){
                                                Users user=usersMapper.getUserByName(getCellValue(cell));
                                                if(user!=null){
                                                    hrRehab.setReinstatementPerson(user.getUserId());
                                                }
                                            }
                                            break;
                                        case 1:
                                            //担任职务
                                            hrRehab.setNowPosition(getCellValue(cell));
                                            break;
                                        case 2:
                                            //申请日期
                                            hrRehab.setApplicationDate(getCellValue(cell));
                                            break;
                                        case 3:
                                            //实际复职日期
                                            hrRehab.setReappointmentTimeFact(getCellValue(cell));
                                            break;
                                        case 4:
                                            //复职手续办理
                                            hrRehab.setMaterialsCondition(getCellValue(cell));
                                            break;
                                        case 5:
                                            //复职类型
                                            hrRehab.setReappointmentType(getCellValue(cell));
                                            break;
                                        case 6:
                                            //复职部门
                                            List<String> parentList = departmentMapper.getDeptIdByDeptName(getCellValue(cell));
                                            String deptIdByDeptName="";
                                            if(parentList.size()>0){
                                                deptIdByDeptName=parentList.get(0);
                                            }
                                            if(!StringUtils.checkNull(deptIdByDeptName)){
                                                hrRehab.setReappointmentDept(deptIdByDeptName);
                                            }
                                            break;
                                        case 7:
                                            //拟复职日期
                                            hrRehab.setReappointmentTimePlan(String.valueOf(getCellValue(cell)));
                                            break;
                                        case 8:
                                            //工资恢复日期
                                            hrRehab.setFirstSalaryTime(getCellValue(cell));
                                            break;
                                        case 9:
                                            // 复职说明
                                            hrRehab.setReappointmentState(String.valueOf(getCellValue(cell)));
                                            break;
                                        case 10:
                                            // 备注
                                            hrRehab.setRemark(getCellValue(cell));
                                            break;
                                    }
                                }
                            }
                            if (hrRehab != null) {
                                int i1 = hrStaffReinstatementMapper.insertSelective(hrRehab);
                                if(i1>0){
                                    successCount++;
                                }
                            }
                        }
                    }
                } else {
                    json.setMsg("file type error!");
                    json.setFlag(1);
                    return json;
                }
            }
            json.setTotleNum(successCount);
            json.setMsg("ok");
            json.setFlag(0);
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("err");
            json.setFlag(1);
        } finally {
            try {
                if(in!=null){
                    in.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return json;
    }
    private String getCellValue(Cell cell) {

        Object value=null;
        switch (cell.getCellType()){
            case STRING:
                value = cell.getStringCellValue();
                break;
            case NUMERIC:
                value = (int)cell.getNumericCellValue();
                break;
            default:
                value = cell.getStringCellValue();
                break;
        }
        return String.valueOf(value);
    }

    /**
     * 获取复职类型列表
     * 郭心雨
     * 2018.07.24
     * @param parentNo
     * @return
     */
    public ToJson fuZhiList(String parentNo) {
        ToJson toJson =new ToJson();
        List<HrCode> hrCodeList=hrCodeMapper.getSysCode(parentNo);
        if (hrCodeList.size()>0){
            toJson.setObj(hrCodeList);
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }


    /**
     * 模糊查询+导出
     * @param request
     * @param response
     * @param hrStaffReinstatement
     * @param page
     * @param pageSize
     * @param useFlag
     * @param export
     * @return
     */
    public ToJson<HrStaffReinstatementWithBLOBs> selectList
            (HttpServletRequest request, HttpServletResponse response, HrStaffReinstatementWithBLOBs hrStaffReinstatement, Integer page, Integer pageSize, boolean useFlag, String export) {
        ToJson<HrStaffReinstatementWithBLOBs> toJson = new ToJson<HrStaffReinstatementWithBLOBs>(1,"err");
        OutputStream out = null;
        try{
            if(export==null){
                export="0";
            }
            //分页
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            HashMap<String,Object> map = new HashMap();
            map.put("page", pageParams);
            if (hrStaffReinstatement.getReinstatementPerson()!=null&& hrStaffReinstatement.getReinstatementPerson()!=""){
                //判断用户是否为空并转化字符串
                if(!StringUtils.checkNull(hrStaffReinstatement.getReinstatementPerson().toString())){
                    String fromIds = hrStaffReinstatement.getReinstatementPerson().toString();
                    String substring = fromIds.substring(0,fromIds.indexOf(","));//截取
                    hrStaffReinstatement.setReinstatementPerson(substring);
                }
            }else{
                map.put("reinstatementPerson",null);
            }
            map.put("hrStaffReinstatement", hrStaffReinstatement);
            List<HrStaffReinstatementWithBLOBs> list=hrStaffReinstatementMapper.selAllRehabMo(map);
            for(HrStaffReinstatementWithBLOBs HrStaff:list){
                //查创建者用户名
                if(HrStaff.getCreateUserId()!=null&&HrStaff.getCreateUserId()!=""){
                    Users u=usersMapper.getUsersByuserId(HrStaff.getCreateUserId());
                    if(u!=null) {
                        HrStaff.setCreateUserId(u.getUserName());
                    }
                }else{
                    HrStaff.setCreateUserId("用户不存在");
                }
                //查复职人员
                if(HrStaff.getReinstatementPerson()!=null&&HrStaff.getReinstatementPerson()!=""){
                    Users u=usersMapper.getUsersByuserId(HrStaff.getReinstatementPerson());
                    if(u!=null) {
                        HrStaff.setReinstatementPerson(u.getUserName());
                    }
                }else{
                    HrStaff.setReinstatementPerson("用户不存在");
                }
                //查部门名称
                if (HrStaff.getReappointmentDept()!=null){
                    String[] depts=HrStaff.getReappointmentDept().split(",");
                    for (String dept:depts){
                        String deptName=departmentMapper.departmentOneSelect(Integer.parseInt(dept));
                        if(!"".equals(deptName)&&deptName!=null){
                            HrStaff.setReappointmentTypeStr(deptName);
                            HrStaff.setReappointmentDept(deptName);
                        }else{
                            HrStaff.setReappointmentTypeStr("该部门已删除");
                        }
                    }
                }else{
                    HrStaff.setReappointmentTypeStr("该部门已删除");
                }
            }
            if(list != null){
                if (list.size() > 0) {
                    for (HrStaffReinstatementWithBLOBs le : list) {
                        List<Attachment> attachments = GetAttachmentListUtil.returnAttachment(le.getAttachmentName(), le.getAttachmentId(), "xoa" + (String) request.getSession().getAttribute("loginDateSouse"), GetAttachmentListUtil.WORKEXPERIENCE);
                        le.setAttachmentList(attachments);

                    }
                }
            }
            toJson.setObj(list);
            toJson.setTotleNum(pageParams.getTotal());
            toJson.setMsg("列表查询成功");
            toJson.setFlag(0);
            if(export.equals("1")) {
                HSSFWorkbook tableWork = ExcelUtil.makeExcelHead("hr_rehab", 12);
                String[] secondTitles = {"姓名", "担任职务","申请日期",
                        "实际复职日期","复职手续办理","复职类型",
                        "复职部门","拟复职日期","工资恢复日期",
                        "复职说明","备注"};
                HSSFWorkbook excelWork = ExcelUtil.makeSecondHead(tableWork, secondTitles);
                String[] beanProperty = {"reinstatementPerson","nowPosition","applicationDate",
                        "reappointmentTimeFact","materialsCondition","reappointmentType",
                        "reappointmentDept","reappointmentTimePlan","firstSalaryTime",
                        "reappointmentState", "remark"};
                HSSFWorkbook workbook = ExcelUtil.exportExcelData(excelWork, list, beanProperty);
                response.setContentType("text/html;charset=UTF-8");
                out = response.getOutputStream();
                String filename = "hr_rehab.xls"; //考虑多语言
                filename = FileUtils.encodeDownloadFilename(filename,
                        request.getHeader("user-agent"));
                response.setContentType("application/vnd.ms-excel");
                response.setHeader("content-disposition",
                        "attachment;filename=" + filename);
                workbook.write(out);
                out.flush();
                out.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        } finally {
            try {
                if(out!=null){
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return toJson;
    }


    /**
     * 查询当前登陆用户数据
     */
    public List<HrStaffReinstatementWithBLOBs> getUserName(HttpServletRequest request,String userId){

        List<HrStaffReinstatementWithBLOBs> hrRehabList=hrStaffReinstatementMapper.getHrStaffContractList(userId);
        for(HrStaffReinstatementWithBLOBs hrStaff:hrRehabList){
            //附件处理
            List<Attachment> attachmentList= GetAttachmentListUtil.returnAttachment(hrStaff.getAttachmentName(),hrStaff.getAttachmentId(),"xoa" + (String) request.getSession().getAttribute("loginDateSouse"), GetAttachmentListUtil.WORKEXPERIENCE);
            hrStaff.setAttachmentList(attachmentList);
            if (hrStaff.getReappointmentDept()!=null){
                String[] depts=hrStaff.getReappointmentDept().split(",");
                for (String dept:depts){
                    String deptName=departmentMapper.departmentOneSelect(Integer.parseInt(dept));
                    if(!"".equals(deptName)&&deptName!=null){
                        hrStaff.setReappointmentTypeStr(deptName);
                    }else{
                        hrStaff.setReappointmentTypeStr("该部门已删除");
                    }
                }
            }else{
                hrStaff.setReappointmentTypeStr("该部门已删除");
            }
            //查创建者用户名
            if(hrStaff.getCreateUserId()!=null&&hrStaff.getCreateUserId()!=""){
                Users u=usersMapper.getUsersByuserId(hrStaff.getCreateUserId());
                hrStaff.setCreateUserId(u.getUserName());
            }else{
                hrStaff.setCreateUserId("用户不存在");
            }
            //查复职人员用户名
            if(hrStaff.getReinstatementPerson()!=null&&hrStaff.getReinstatementPerson()!=""){
                Users u=usersMapper.getUsersByuserId(hrStaff.getReinstatementPerson());
                hrStaff.setReinstatementPerson(u.getUserName());
            }else{
                hrStaff.setReinstatementPerson("用户不存在");
            }
        }
        return hrRehabList;
    }


    /**
     * 创建者：戚中校
     * 方法作用：根据条件查询数量
     * @param
     * @param deptId(传入的多个部门的编号)
     * @return 返回的json字符串中  nums是返回的结果的数量
     *
     */
    public ToJson<HrStaffReinstatement> selectNumByCon(HrStaffReinstatement record, Integer[] deptId) {
        ToJson toJson = new ToJson();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            if (deptId != null && deptId.length > 0){
                map.put("deptId",deptId);
            }
            map.put("record",record);
            List<HrStaffReinstatement> list = hrStaffReinstatementMapper.selectNumByCon(map);

            if(list.size() >= 0){
                toJson.setObj(list);
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }else{
                toJson.setMsg("err");
                toJson.setFlag(1);
            }

        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }
    public  ToJson<HrStaffReinstatementWithBLOBs> getBystaffName(String staffName, Integer page, Integer pageSize, boolean useFlag){
        ToJson<HrStaffReinstatementWithBLOBs> json=new ToJson<HrStaffReinstatementWithBLOBs>();
        //分页
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        HashMap<String,Object> map = new HashMap();
        map.put("pageParams", pageParams);
        map.put("staffName",staffName);
        try{
            List<HrStaffReinstatementWithBLOBs> list=hrStaffReinstatementMapper.getBytaffName(map);
            if(list.size()>0){
                for(HrStaffReinstatementWithBLOBs rein:list){
                    if(rein.getReinstatementPerson()!=null){
                        Users user = usersMapper.findUsersByuserId(rein.getReinstatementPerson()); //根据 id 找名字
                        rein.setReinstatementPerson(user.getUserName());
                    }
                }
                json.setObj(list);
            }
            json.setTotleNum(hrStaffReinstatementMapper.getBytaffNameCount(staffName));
            json.setFlag(0);
            json.setMsg("true");
        }catch (Exception e){
            e.printStackTrace();
            json.setMsg("err");
            json.setFlag(1);
        }
        return json;
    }
}
